package com.hiof.location.earcon;

import android.content.Context;
import android.speech.tts.TextToSpeech;
import android.widget.Toast;
import com.hiof.Configuration;
import com.hiof.utility.Utility;
import com.hiof.voiceguide.Speakable;

import java.util.Locale;

/**
 * Created with IntelliJ IDEA.
 * User: manish
 * Date: 4/20/12
 * Time: 1:42 AM
 * To change this template use File | Settings | File Templates.
 */
public class EarconPlayer implements TextToSpeech.OnInitListener {

    private TextToSpeech tts;
    private String earcon;

    public EarconPlayer() {
        init(Configuration.getInstance().getCurrentContext());
    }

    public void init(Context context) {
        tts = new TextToSpeech(context, this);
    }

    public void stop() {
        if (null != tts) {
            tts.stop();
        }
    }

    public void playEarcon() {
        tts.playEarcon(earcon, TextToSpeech.QUEUE_FLUSH, null);
    }

    public void addEarcon(String earcon, String packagename, int resourceId) {
        this.earcon = earcon;
        tts.addEarcon(earcon, packagename, resourceId);
    }

    @Override
    public void onInit(int status) {
        Toast.makeText(Configuration.getInstance().getCurrentContext(), "TTS started for earcon", Toast.LENGTH_SHORT).show();
        // status can be either TextToSpeech.SUCCESS or TextToSpeech.ERROR.
        if (status == TextToSpeech.SUCCESS) {
            Utility.debug(this.getClass().toString(), "onIit(): earcon initialization success");
        } else {
            Utility.error(this.getClass().toString(), "Could not initialize TextToSpeech for earcon.");
        }
    }
}
